<template>
	<view class="home">
		<view class="img">
			<image mode="scaleToFill" :src="MainList.imgUrl" style="width: 100%;height:350px"></image>
		</view>
		<view class="MainConent">
			<view class="prcie">
				<view class="productPrice">
					¥{{MainList.price}}
				</view>
				<view class="Nowsale" style="margin-right: 30px;">
					已售 {{MainList.salesNumber}}
				</view>
			</view>
			<view class="Name">
				<view class="Title" style="font-size: 20px;color: #000;">
					{{MainList.name}}
				</view>
			</view>
			<view class="miaoshu">
				<view class="miaoshu" v-if="MainList.description">
					{{MainList.description}}
				</view>
			</view>
		</view>
		<view class="buy" style="position: fixed;width: 100%;">
			<u-button @click="open">立即购买</u-button>
		</view>
		<u-modal v-model="show" :title-style="{color: 'red'}" title="确认购买" cancel-text="取消" show-cancel-button @confirm="queding">
			<view class="slot-content">
				<view>请选择您的购买数量</view>
				<u-number-box v-model="Buyvalue"></u-number-box>
			</view>
		</u-modal>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>

<script>
	import { getNormalstoreList,poststoreList,poststoreListDingDan } from '../../../api/store/api';
	export default {
		data(){
			return{
				id:'',
				MainList:{},
				show:false,
				Buyvalue:0,
				productID:0
			}
		},
		methods:{
			GetNowList() {
				getNormalstoreList(this.id).then(res => {
					this.MainList = res.data
					console.log(this.MainList)
				})
			},
			open() {
				poststoreListDingDan(this.id).then(res => {
					this.show = true;
					this.productID = res.data
				})
			},
			queding(){
				if(this.Buyvalue){
					this.BuystoreList()
				}
			},
			BuystoreList(){
				poststoreList({
					id:this.productID,
					quantity: this.Buyvalue
				}).then(res => {
					if(res.code == 200){
						this.showToast('购买成功','success')
					}else{
						this.showToast('购买失败','error')
					}
				})
			},
			showToast(msg,type) {
				this.$refs.uToast.show({
					title: msg,
					type: type,
				})
			}
		},
		onLoad(options){
			this.id = options.id;
			this.GetNowList();
		}
	}
</script>

<style>
	.home{
		    padding: 0 10px;
		    background-color: #fff;
		    height: 95vh;
	}
	.img{
		padding: 10px 0;
	}
	.MainConent{
		display: flex;
		flex-direction: column;
		gap:10px;
	}
	.prcie{
		display: flex;
		justify-content: space-between;
		align-items: flex-end;
	}
	
	.productPrice{
		font-size: 25px;
		color: red;
	}
	
	.buy{
		position: fixed;
		width: 100%;
		left: 0;
		bottom: 0;
	}
	.slot-content {
		display: flex;
		font-size: 14px;
		margin: 20px;
		gap: 10px;
		align-items: center;
	}
</style>